package team;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;

/**
 * Display initial screen for the program
 * @author YongXiang Tang, Sean Peng
 *
 */
public class InitialFrame extends JFrame {
	
	private static final long serialVersionUID = 1L;
	private JFrame frame = this; 
	
	/**
	 * Constructor for InitialFrame
	 */
	public InitialFrame() {
		
		JPanel userButtonPanel = new JPanel();
		JButton normalButton = new JButton("	Normal User Login	");
		JButton makerButton = new JButton ("	Maker User Login	");
		JButton partButton = new JButton ("		Vendor User Login	");
		
		/* buttons click actions*/
		normalButton.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				
				AutoMakerFrame autoMakerFrame = new AutoMakerFrame(frame, false);
				frame.setVisible(false);
			}
			
		});
		
		/* buttons click actions*/
		makerButton.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				
				AutoMakerFrame autoMakerFrame = new AutoMakerFrame(frame, true);
				frame.setVisible(false);
			}
			
		});
		
		/* button click actions */
		partButton.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				PartModFrame partModFrame = new PartModFrame(frame);
				frame.setVisible(false);
			}
		});
		
		JPanel createButtonPanel = new JPanel();
		JButton addCarButton = new JButton(" Create a car	");
		JButton addPartButton = new JButton ("	Create a part   ");
		
		//button actions
		addCarButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				AddNewAutoFrame addFrame = new AddNewAutoFrame(frame, true);
				frame.setVisible(false);
			}
		});
		
		//button actions
		addPartButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				AddNewPartFrame addFrame = new AddNewPartFrame(frame);
				frame.setVisible(false);
			}
			
		});
		
		
		/* set panel layout */
		userButtonPanel.setLayout(new GridLayout(0,1));
		userButtonPanel.add(normalButton);
		userButtonPanel.add(makerButton);
		userButtonPanel.add(partButton);
		userButtonPanel.setBorder(BorderFactory.createTitledBorder("User Login: "));
//		createButtonPanel.setLayout(new GridLayout(0,1));
//		createButtonPanel.add(addCarButton);
//		createButtonPanel.add(addPartButton);
//		createButtonPanel.setBorder(BorderFactory.createTitledBorder("Create a car/part: "));
		this.setLayout(new GridBagLayout());
		this.getContentPane().add(userButtonPanel, new GridBagConstraints());
//		this.getContentPane().add(createButtonPanel, new GridBagConstraints());

		
		
		/* set window's properties */
		this.setTitle("Initial Frame");
		this.setSize(400,400);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		
		//Create Maker Hash Table
		AutoMaker.createMakerTable();
	}// end of InitialFrame Constructor
	
} // class InitialFrame